
package br.eti.busarello;

import java.util.Properties;

import com.googlecode.flyway.core.Flyway;
import com.googlecode.flyway.core.api.MigrationInfo;
import com.googlecode.flyway.core.api.MigrationVersion;

public class FlywayExecutor {
	
	
	public FlywayExecutor() {
		Flyway flyway = new Flyway();

		flyway.configure(getProperties());
		
		System.out.println("Target: "+flyway.getTarget());
				
		MigrationInfo[] applied = flyway.info().applied();
		
		System.out.println("Actual: "+flyway.info().current());
		
		for (MigrationInfo migrationInfo : applied) {
			System.out.println("Apllied: "+migrationInfo);
    }
		
		applied = flyway.info().pending();
		
		for (MigrationInfo migrationInfo : applied) {
			System.out.println("Pending: "+migrationInfo.getVersion());
    }
		
		flyway.setValidateOnMigrate(true);
		System.out.println("isInitOnMigrate: "+flyway.isInitOnMigrate());
		
		//flyway.clean();
		
		//flyway.setTarget(new MigrationVersion("2"));
		
		System.out.println("Aplicados: "+flyway.migrate());
		
  }
	
	private Properties getProperties(){
    Properties properties = new Properties();
    properties.setProperty("flyway.user", "root");
    properties.setProperty("flyway.password", "testando");
    properties.setProperty("flyway.url", "jdbc:mysql://localhost:3306/teste");
    properties.setProperty("flyway.driver", "com.mysql.jdbc.Driver");
    
    return properties;
	}
	
	public static void main(String[] args) {
	  new FlywayExecutor();
	  System.exit(0);
  }
	
}